package com.attendancesystem.config;

import com.attendancesystem.model.Attendance.Status;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;

public class StatusAdapter extends TypeAdapter<Status> {
    @Override
    public void write(JsonWriter out, Status value) throws IOException {
        // 直接序列化中文状态值
        out.value(value.getChineseName());
        System.out.println("正在序列化状态：" + value.getChineseName());

    }

    @Override
    public Status read(JsonReader in) throws IOException {
        // 从中文状态值反序列化
        return Status.fromChineseName(in.nextString());
    }
}
